﻿using System;
using System.Collections.Generic;
using System.Text;
using jade.core;
using jade.wrapper;
using MarketSimulator.Utils.Market;
using MarketSimulator.Utils.Maps;
using System.Windows.Forms;

namespace MarketSimulator.Agents
{
    /// <summary>
    /// Agent Creator
    /// </summary>
    public class AgentCreator
    {
        public Profile ProfileImpl { get; private set; }

        public Runtime RunTime { get; private set; }

        public jade.wrapper.AgentContainer Container { get; private set; }

        public Form TheForm { get; private set; }

        public AgentCreator(Form theForm)
        {
            ProfileImpl = new ProfileImpl();
            RunTime = Runtime.instance();
            Container = RunTime.createMainContainer(ProfileImpl);
            TheForm = theForm;
        }

        /// <summary>
        /// Assistant agent
        /// </summary>
        /// <param name="agentChat"></param>
        /// <returns></returns>
        public AgentController GetAssistantAgent(Action<string> agentChat, string fqn)
        {
            AgentController newAgent = Container.createNewAgent("ASSIST", fqn, new object[] { TheForm, agentChat });
            newAgent.start();
            return newAgent;
        }

        /// <summary>
        /// Create Seller Agent
        /// </summary>
        /// <param name="sellerChat"></param>
        /// <param name="agentChat"></param>
        /// <param name="names"></param>
        public void StartSellerAgents(Action<string> sellerChat, Action<string> agentChat, params string[] names)
        {
            foreach (var name in names)
            {
                AgentController newAgent = Container.createNewAgent(name, " MarketSimulator.Agents.Agents.SellerAgent", new object[] { TheForm, sellerChat, agentChat });
                newAgent.start();
            }
        }

        /// <summary>
        /// Create Seller Agent
        /// </summary>
        /// <param name="sellerChat"></param>
        /// <param name="agentChat"></param>
        /// <param name="names"></param>
        public void StartStorageAgents(Action<string> storageChat, Action<string> agentChat, params string[] names)
        {
            foreach (var name in names)
            {
                AgentController newAgent = Container.createNewAgent(name, " MarketSimulator.Agents.Agents.StorageAgent", new object[] { TheForm, storageChat, agentChat });
                newAgent.start();
            }
        }


        /// <summary>
        /// Create Seller Agent
        /// </summary>
        /// <param name="sellerChat"></param>
        /// <param name="agentChat"></param>
        /// <param name="names"></param>
        public void StartBuyerAgents(Action<string> buyerChat, Action<string> agentChat, params string[] names)
        {
            foreach (var name in names)
            {
                AgentController newAgent = Container.createNewAgent(name, " MarketSimulator.Agents.Agents.BuyerAgent", new object[] { TheForm, buyerChat, agentChat });
                newAgent.start();
            }
        }


        /// <summary>
        /// Create Seller Agent
        /// </summary>
        /// <param name="sellerChat"></param>
        /// <param name="agentChat"></param>
        /// <param name="names"></param>
        public void StartTransporterAgents(Action<string> transporterChat, Action<string> agentChat, params string[] names)
        {
            foreach (var name in names)
            {
                AgentController newAgent = Container.createNewAgent(name, " MarketSimulator.Agents.Agents.TransporterAgent", new object[] { TheForm, transporterChat, agentChat });
                newAgent.start();
            }
        }
    }
}
